package cn.hxlc.tie.demo.modular.zr.material.controller;/*
 @author rui
 @date 2021/7/15 --18:51
*/


import cn.hxlc.tie.demo.modular.zr.material.entity.MaterialGroup;
import cn.hxlc.tie.demo.modular.zr.material.model.params.MaterialGroupParam;
import cn.hxlc.tie.demo.modular.zr.material.model.params.MaterialParam;
import cn.hxlc.tie.demo.modular.zr.material.model.result.MaterialGroupResult;
import cn.hxlc.tie.demo.modular.zr.material.service.MaterialGroupService;
import cn.hxlc.tie.libs.scanner.annotation.GetResource;
import cn.hxlc.tie.libs.scanner.annotation.PostResource;
import cn.hxlc.tie.libs.scanner.stereotype.ApiResource;
import cn.hxlc.tie.model.page.PageResult;
import cn.hxlc.tie.model.web.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name="物料分类_树",path="/materialTree")
@Api(tags="物料")
public class ZrProductGroupController {

    @Autowired
    private MaterialGroupService materialGroupService;

    @GetResource(name="树查询",path="/queryTree",requiredPermission = false,requiredLogin = true)
        @ApiOperation(value ="树查询", response= MaterialGroupResult.class)
        public ResponseData queryTree(){
           return ResponseData.success(this.materialGroupService.queryTree());
            }
     @GetResource(name = "分页查询列表",path = "/queryList",requiredLogin = false,requiredPermission = false)
     @ApiOperation(value="分页查询列表")
     public ResponseData  queryList(MaterialGroupParam param){
        PageResult<MaterialGroupResult> pageBySpec=materialGroupService.findPageBySpec(param);
        return ResponseData.success(pageBySpec);
     }
    @PostResource(name="添加",path = "/addOne",requiredPermission = false,requiredLogin = false)
    @ApiOperation(value = "添加")
    public ResponseData addOne(@RequestBody MaterialGroupParam materialGroupParam){
        materialGroupService.addOne(materialGroupParam);
        return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,"添加成功","null");
    }
    @PostResource(name = "修改",path = "/update",requiredPermission = false,requiredLogin = false)
    @ApiOperation(value="修改")
    public ResponseData update(@RequestBody MaterialGroupParam materialGroupParam){
       materialGroupService.updateOne(materialGroupParam);
       return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,"修改成功","null");
    }

    @PostResource(name="删除",path = "/delete",requiredPermission = false,requiredLogin = false)
    @ApiOperation(value="删除")
    public ResponseData delete(@RequestParam Long fid){
        materialGroupService.deleteOne(fid);
        return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,"删除成功","null");
    }
}
